package com.xingkeduo.business.order.controller;

import com.alibaba.fastjson.JSON;
import com.google.zxing.WriterException;
import com.xingkeduo.business.order.domain.OrderDomainService;
import com.xingkeduo.business.order.domain.OrderQueryService;
import com.xingkeduo.business.order.domain.OrderRefundDomainService;
import com.xingkeduo.business.order.service.OrderService;
import com.xingkeduo.dto.PriceDto;
import com.xingkeduo.dto.enums.OrderQueryStatus;
import com.xingkeduo.dto.enums.OrderQueryTypeEnum;
import com.xingkeduo.dto.param.*;
import com.xingkeduo.dto.payment.PayeeOrderResponseDto;
import com.xingkeduo.dto.response.*;
import com.xingkeduo.pojo.enums.GatheringType;
import com.xingkeduo.pojo.table.Order;
import com.xingkeduo.util.pojo.exception.BusinessException;
import com.xingkeduo.utils.PageResponseDTO;
import com.xingkeduo.utils.QRCodeGenerator;
import com.xingkeduo.utils.QRCodeUtils;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.xingkeduo.utils.Constant.API_URL_PREFIX;

/**
 * @author chi  2019-02-13 15:10
 **/
@RestController
@RequestMapping(API_URL_PREFIX + "/order")
@Slf4j
public class OrderApiController {

    @Resource
    private OrderQueryService orderQueryService;
    @Resource
    private OrderDomainService orderDomainService;
    @Resource
    private OrderService orderService;
    @Resource
    private OrderRefundDomainService orderRefundDomainService;

    ////////////////////////////////////////用户端

    /**
     * 新建订单(用户端)
     *
     * @param orderInitDto
     * @return
     */
    @PostMapping("")
    public ResponseEntity insert(@RequestBody @Valid OrderInitDto orderInitDto) {
        log.info("insert order:{}", JSON.toJSONString(orderInitDto));
        String orderId = orderDomainService.initOrder(orderInitDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderId), HttpStatus.OK);
    }

    /**
     * 新建代 付订单
     *
     * @param payForAnotherInitDto
     * @return
     */
    @PostMapping("/pay/for_another")
    public ResponseEntity payForAnother(@RequestBody @Valid PayForAnotherInitDto payForAnotherInitDto, HttpServletRequest request) {
        log.info("insert payForAnother:{}", payForAnotherInitDto);
        ResponseUtils responseUtils = orderDomainService.payForAnother(payForAnotherInitDto, getCustomerIp(request));
        return new ResponseEntity<>(responseUtils, HttpStatus.OK);
    }

    /**
     * 新建随星付
     *
     * @return
     */
    @PostMapping("/suixin_pay")
    public ResponseEntity suixin_pay(@RequestBody @Valid SuixinPayInitDto suixinPayInitDto) {
        log.info("suixin_pay:{}", suixinPayInitDto);
        Map map = orderDomainService.suixinPay(suixinPayInitDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(map), HttpStatus.OK);
    }

    /**
     * 更改预约时间(用户端)
     *
     * @return
     */
    @PutMapping("/appointment")
    public ResponseEntity appointment(@RequestBody @Valid OrderAppointmentDto orderAppointmentDto) {
        log.info("appointment order:{}", JSON.toJSONString(orderAppointmentDto));
        orderDomainService.editAppointment(orderAppointmentDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 更改发型id(用户端)
     *
     * @return
     */
    @PutMapping("/hair")
    public ResponseEntity hair(@RequestBody @Valid OrderHairDto orderHairDto) {
        log.info("hair order:{}", JSON.toJSONString(orderHairDto));
        orderDomainService.editHair(orderHairDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 根据订单No 更改发型id(用户端)
     *
     * @return
     */
    @PutMapping("/hair/order/no")
    public ResponseEntity hairByOrderNo(@RequestBody @Valid OrderHairDto orderHairDto) {
        log.info("hair order:{}", JSON.toJSONString(orderHairDto));
        orderDomainService.editHairByNo(orderHairDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 取消订单(用户端)
     *
     * @return
     */
    @PutMapping("/cancel")
    public ResponseEntity cancel(String id) {
        log.info("cancel order:{}", JSON.toJSONString(id));
        orderDomainService.cancel(id);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 取消订单（小程序）
     * @param userId  用户id
     * @param orderNo  订单号
     * @return
     */
    @PutMapping("/cancelOrder")
    public ResponseEntity cancelOrder(String userId,String orderNo) {
        orderDomainService.cancelOrder(userId,orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 过号后重新预约(用户端)
     *
     * @param
     * @return
     */
    @PutMapping("/reApply")
    public ResponseEntity reApply(@RequestBody @Valid OrderAppointmentDto orderAppointmentDto) {
        log.info("reApply order:{}", JSON.toJSONString(orderAppointmentDto));
        orderDomainService.reApply(orderAppointmentDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    ////////////////////////////////////////发型师端

    /**
     * 手动操作叫号
     *
     * @return
     */
    @PutMapping("/announceNumber")
    public ResponseEntity announceNumber(@RequestBody @Valid OrderIdParamDto orderIdParamDto) {
        log.info("announceNumber order:{}", JSON.toJSONString(orderIdParamDto));
        long i = orderDomainService.announceNumber(orderIdParamDto.getId());
        return new ResponseEntity<>(ResponseUtils.getSuccess(i), HttpStatus.OK);
    }

    /**
     * 手动操作过号,系统过号
     *
     * @return
     */
    @PutMapping("/overNumber")
    public ResponseEntity overNumber(@RequestBody @Valid OrderIdParamDto orderIdParamDto) {
        log.info("overNumber order:{}", JSON.toJSONString(orderIdParamDto));
        orderDomainService.overNumber(orderIdParamDto.getId(),true);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 开始服务
     *
     * @return
     */
    @PutMapping("/inService")
    public ResponseEntity inService(@RequestBody @Valid OrderInserviceDto orderInserviceDto) {
        log.info("inService order:{}", JSON.toJSONString(orderInserviceDto));
        orderDomainService.inService(orderInserviceDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 发型师完成服务
     *
     * @return
     */
    @PutMapping("/endService")
    public ResponseEntity endService(@RequestBody @Valid OrderIdParamDto orderIdParamDto) {
        log.info("endService order:{}", JSON.toJSONString(orderIdParamDto));
        orderDomainService.endService(orderIdParamDto.getId());
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 发型师手动验票
     *
     * @return
     */
    @GetMapping("/ticket/check")
    public ResponseEntity check(String ticketCode, String storeId) {
        log.info("check:{}", ticketCode);
        OrderAdminResponseDto orderResponseDto = orderDomainService.checkTicket(ticketCode, storeId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("exist", orderResponseDto != null);
        map.put("orderInfo", orderResponseDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(map), HttpStatus.OK);
    }




    /**
     * 获取验票码(用户端)
     *
     * @return
     */
    @GetMapping("/ticket/obtain/code")
    public ResponseEntity obtainCode(String orderNo) {
        RefreshCodeResponseDto refreshCodeResponseDto = orderDomainService.obtainTicketNo(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(refreshCodeResponseDto), HttpStatus.OK);
    }


    ////////////////////////随信付




    /**
     * 支付回调,  支付成功
     *
     * @return
     */
    @PostMapping("/notify/paid")
    public ResponseEntity paid(@RequestBody PayeeOrderResponseDto payeeOrderResponseDto) {
        log.info("paid notify order:{}", JSON.toJSONString(payeeOrderResponseDto));
        orderDomainService.paid(payeeOrderResponseDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 微信退款回调
     *
     * @return
     */
    @PostMapping("/notify/refund")
    public ResponseEntity refund(@RequestBody PayeeOrderResponseDto payeeOrderResponseDto) {
        log.info("微信退款回调 paid notify order:{}", JSON.toJSONString(payeeOrderResponseDto));
        orderRefundDomainService.refund(payeeOrderResponseDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }

    /**
     * 支付成功查询
     *
     * @return
     */
    @GetMapping("/paid/status")
    public ResponseEntity paidStatus(String id) {
        log.info("paid order:{}", JSON.toJSONString(id));
        OrderPayStatusDto orderPayStatusDto = orderDomainService.paidStatus(id);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderPayStatusDto), HttpStatus.OK);
    }


    //////////////////////////////////查询相关


    /**
     * 用户端列表查询(用户端)
     *
     * @param orderUserQueryDto
     * @return
     */
    @GetMapping("/user/query")
    public ResponseEntity userQuery(OrderUserQueryDto orderUserQueryDto) {
        log.info("userQuery:{}", JSON.toJSONString(orderUserQueryDto));
        PageResponseDTO<OrderUserResponseDto> orderUserResponseDtos = orderQueryService.userQuery(orderUserQueryDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderUserResponseDtos), HttpStatus.OK);
    }

    /**
     * 用户端订单详情(用户端)
     *
     * @return
     */
    @GetMapping("/user/query/detail")
    public ResponseEntity userQuery(String id) {
        OrderUserDetailResponseDto orderUserDetailResponseDto = orderQueryService.userDetailQuery(id);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderUserDetailResponseDto), HttpStatus.OK);
    }

    /**
     * 发型师端今日订单,无分页
     *
     * @param queryDto
     * @return
     */
    @GetMapping("/admin/query/today")
    public ResponseEntity adminTodayQuery(OrderAdminQueryDto queryDto) {
        log.info("userQuery:{}", JSON.toJSONString(queryDto));
        List<OrderAdminResponseDto> orderAdminResponseDtos = orderQueryService.adminTodayQuery(queryDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderAdminResponseDtos), HttpStatus.OK);
    }


    /**
     * 发型师端历史预约订单查询,带分页
     *
     * @param queryDto
     * @return
     */
    @GetMapping("/admin/query/appointment")
    public ResponseEntity adminHistoryAppointmentQuery(OrderAdminHistoryQueryDto queryDto) {
        log.info("/admin/query/appointment:{}", JSON.toJSONString(queryDto));
        PageResponseDTO<OrderAdminResponseDto> orderAdminResponseDtoPageResponseDTO = orderQueryService.adminHistoryQuery(queryDto, OrderQueryTypeEnum.APPOINTMENT);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderAdminResponseDtoPageResponseDTO), HttpStatus.OK);
    }

    /**
     * 发型师端历史服务订单查询,带分页
     *
     * @param queryDto
     * @return
     */
    @GetMapping("/admin/query/service")
    public ResponseEntity adminHistoryServiceQuery(OrderAdminHistoryQueryDto queryDto) {
        log.info("/admin/query/service:{}", JSON.toJSONString(queryDto));
        PageResponseDTO<OrderAdminResponseDto> orderAdminResponseDtoPageResponseDTO = orderQueryService.adminHistoryQuery(queryDto, OrderQueryTypeEnum.SERVICE);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderAdminResponseDtoPageResponseDTO), HttpStatus.OK);
    }


    /**
     * 发型师端  当前正在服务的订单
     */
    @GetMapping("/admin/inService/query")
    public ResponseEntity inServiceQuery(String adminId) {
        log.info("inService query:{}", JSON.toJSONString(adminId));
        OrderAdminResponseDto orderAdminResponseDto = orderQueryService.inServiceQuery(adminId);

        HashMap<String, Object> map = new HashMap<>();
        map.put("exist", orderAdminResponseDto != null);
        map.put("orderInfo", orderAdminResponseDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(map), HttpStatus.OK);
    }

    /**
     * 发型师端 订单详情
     */
    @GetMapping("/admin/query/detail")
    public ResponseEntity detailQuery(String id,String orderNo) {
        log.info("admin query detail:{},{}", id, orderNo);
        OrderAdminDetailResponseDto orderAdminResponseDto = orderQueryService.adminDetail(id, orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderAdminResponseDto), HttpStatus.OK);
    }

    /**
     * 发型师端  根据订单号查询
     * @param orderNo
     * @return
     */
    @GetMapping("/admin/query/single")
    public ResponseEntity detailQuery(String orderNo) {
        OrderAdminResponseDto adminOrder = orderQueryService.getAdminOrder(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(adminOrder), HttpStatus.OK);
    }


    /**
     * 收款原因查询
     *
     * @return
     */
    @GetMapping("/admin/gathering/list")
    public ResponseEntity inServiceQuery() {
        Map<String, String> stringStringMap = GatheringType.typeMap();
        return new ResponseEntity<>(ResponseUtils.getSuccess(stringStringMap), HttpStatus.OK);
    }


    /**
     * 发型师今日订单数量
     *
     * @return
     */
    @GetMapping("/admin/today/count")
    public ResponseEntity todayCount(String adminId,String storeId) {

        HashMap<OrderQueryStatus, Integer> todayCount = orderQueryService.getTodayCount(adminId,storeId);

        return new ResponseEntity<>(ResponseUtils.getSuccess(todayCount), HttpStatus.OK);
    }


    /**
     * 根据orderNo获得详情
     *
     * @return
     */
    @GetMapping("/info")
    public ResponseEntity queryByOrderNO(String orderNo) {
        OrderDetailResponseDto orderDetailResponseDto = orderService.queryByOrderNO(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderDetailResponseDto), HttpStatus.OK);
    }


    /**
     * 根据用户id和cityid查询用户查上一单信息
     *
     * @param orderUserParamDto
     * @return
     */
    @GetMapping("/query/info")
    public ResponseEntity queryOrderInfo(@Valid OrderUserParamDto orderUserParamDto) {
        String storeId = orderService.queryOrderInfo(orderUserParamDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(storeId), HttpStatus.OK);
    }

    /**
     * 根据用户id获取 服务次数、距离最后一次服务的天数(小程序)
     * @param userId
     * @return
     */
    @GetMapping("/query/services")
    public ResponseEntity orderServices(String userId){
        OrderServiceDto orderServiceDto = orderService.orderServices(userId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderServiceDto), HttpStatus.OK);
    }


    /**
     *获取未支付订单orderNo（小程序）
     * @param userId
     * @return
     */
    @GetMapping("/query/nopay")
    public ResponseEntity getNotPayOrderNo(String userId){
        String orderNo = orderService.getNotPayOrderNo(userId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderNo), HttpStatus.OK);
    }

    /**
     * 根据用户id 店铺id 判断该店铺id是否是该用户上次服务的店铺 （小程序）
     * @param userId
     * @param storeId
     * @return
     */
    @GetMapping("/last/server")
    public ResponseEntity lastService(String userId,String storeId){
        boolean bf= orderService.lastService(userId,storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(bf), HttpStatus.OK);
    }


    /**
     *获取未支付订单orderInfo（小程序）
     * @param userId
     * @return
     */
    @GetMapping("/query/nopay/info")
    public ResponseEntity getNotPayOrderInfo(String userId){
        Order orderNo = orderService.getNotPayOrderInfo(userId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderNo), HttpStatus.OK);
    }


    /**
     * 调用支付
     * @param paymentParam
     * @param httpServletRequest
     * @return
     */
    @PostMapping("/to_pay")
    public ResponseEntity toPay(@RequestBody PaymentParam paymentParam, HttpServletRequest httpServletRequest){
        ResponseUtils responseUtils = orderDomainService.toPay(paymentParam, getCustomerIp(httpServletRequest));
        return new ResponseEntity<>(responseUtils, HttpStatus.OK);
    }


    /**
     * 获取签署者IP
     *
     * @param request 请求地址
     * @return
     */
    private String getCustomerIp(HttpServletRequest request) {
        String ip = request.getHeader("X-Real-IP");
        if (ip != null && !"".equals(ip) && !"unknown".equalsIgnoreCase(ip)) {
            log.info("X-Real-IP" + " " + ip);
            return ip;
        }
        ip = request.getHeader("X-Forwarded-For");
        if (ip != null && !"".equals(ip) && !"unknown".equalsIgnoreCase(ip)) {
            // 多次反向代理后会有多个IP值，第一个为真实IP。
            int index = ip.indexOf(',');
            if (index != -1) {
                return ip.substring(0, index);
            } else {
                log.info("X-Forwarded-For" + " " + ip);
                return ip;
            }
        } else {
            log.info("getRemoteAddr" + " " + request.getRemoteAddr());
            return request.getRemoteAddr();
        }
    }



    /**
     * 根据orderNos 获取订单列表
     * @param orderNos
     * @return
     */
    @GetMapping("/infos")
    public ResponseEntity queryByOrderNos(String[] orderNos) {
        List<OrderDetailResponseDto>  lists = orderService.queryOrders(orderNos);
        return new ResponseEntity<>(ResponseUtils.getSuccess(lists), HttpStatus.OK);
    }


    /**
     * 根据获得门店发型师金额
     * @return
     */
    @GetMapping("/admin/price")
    public ResponseEntity adminPrice(String adminIds,String storeId, String serviceTypeId) {
        Map<String, PriceDto> stringPriceDtoMap = orderDomainService.allPrice(adminIds, storeId, serviceTypeId);
        log.info("/admin/price 返回值:{}", JSON.toJSONString(stringPriceDtoMap));
        return new ResponseEntity<>(ResponseUtils.getSuccess(stringPriceDtoMap), HttpStatus.OK);
    }



    /**
     * 获取用户类型
     * @return
     */
    @GetMapping("/query/user/type")
    public ResponseEntity queryUserType(String userId,String storeId) {
        log.info("获取用户类型 userId:{}", userId);
        log.info("获取用户类型 storeId:{}", storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderService.queryUserType(userId,storeId)), HttpStatus.OK);
    }


    /**
     * 获取二维码
     * @param response
     * @param data_url
     */
    @RequestMapping(value = "/qrcode")
    public void test2(HttpServletResponse response,String data_url){
        BufferedImage bufferedImage = QRCodeUtils.genGR(data_url);

        try {
            ImageIO.write(bufferedImage, "png", response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    /**
     * 去白边的二维码
     * @param response
     * @param data_url
     * @return
     */
    @RequestMapping(value = "/qrcode/nowhite")
    public ResponseEntity<byte[]> qrcode1(HttpServletResponse response,@RequestBody String data_url){
        byte[] qrcode = null;
        try {
            qrcode = QRCodeGenerator.getQRCodeImage(data_url, 360, 360);
        } catch (WriterException e) {
            System.out.println("Could not generate QR Code, WriterException :: " + e.getMessage());
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Could not generate QR Code, IOException :: " + e.getMessage());
        }

        // Set headers
        final HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_PNG);

        return new ResponseEntity<byte[]> (qrcode, headers, HttpStatus.CREATED);

    }



    /**
     * 发型师服务过店铺
     * @return
     */
    @GetMapping("/query/admin/storeList")
    public ResponseEntity adminStoreList(String adminId) {
        return new ResponseEntity<>(ResponseUtils.getSuccess(orderService.adminStoreList(adminId)), HttpStatus.OK);
    }

    /**
     * 店铺服务过的发型师
     * @return
     */
    @GetMapping("/query/admin/adminList")
    public ResponseEntity adminList(String storeId, String type) {
        if("appointment".equals(type)){
            Object o = orderService.adminListAppointment(storeId);
            return new ResponseEntity<>(ResponseUtils.getSuccess(o), HttpStatus.OK);
        }
        Object o = orderService.adminListAdmin(storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(o), HttpStatus.OK);

    }


    /**
     * 根据卡券ids 查询卡券信息
     * @param marketingIds
     * @return
     */
    @GetMapping("/marketing")
    public ResponseEntity marketing(String[] marketingIds,String marketingType) {
        List<OrderDetailResponseDto>  lists = orderService.marketing(marketingIds,marketingType);
        return new ResponseEntity<>(ResponseUtils.getSuccess(lists), HttpStatus.OK);
    }


    /**
     * 评论成功修改订单(用户端)
     *
     * @return
     */
    @PutMapping("/comment")
    public ResponseEntity comment(String orderNo) {
        orderDomainService.edithadComment(orderNo);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 修改活动卡券信息（核对订单）
     * @param orderNo
     * @param marketId
     * @param type
     * @return
     */
    @PutMapping("/change/market")
    public ResponseEntity changeMarket(String orderNo,String marketId,String type) {
        orderDomainService.changeMarket(orderNo,marketId,type);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 更改预约时间(用户端) 支付后
     *
     * @return
     */
    @PutMapping("/appointment/completed")
    public ResponseEntity appointmentCompleted(@RequestBody @Valid OrderAppointmentDto orderAppointmentDto) {
        log.info("appointment order:{}", JSON.toJSONString(orderAppointmentDto));
        orderDomainService.editAppointmentCompleted(orderAppointmentDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 判断卡券信息有没有使用
     * @param userId
     * @return
     */
    @GetMapping("/card/ticket")
    public ResponseEntity cardTick(String userId,String cardTickId,Integer  marketingType) {
        boolean bf = orderDomainService.cardTick(userId,cardTickId,marketingType);
        return new ResponseEntity<>(ResponseUtils.getSuccess(bf), HttpStatus.OK);
    }


    /**
     * 当天服务未开始的订单 自动过号
     * @return
     */
    @GetMapping("/orver")
    public ResponseEntity overNumber() {
        orderDomainService.consumeMessage();
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 获取店铺待审核订单数量
     * @param storeId
     * @return
     */
    @GetMapping("/refundApply")
    public ResponseEntity refundApply(String storeId) {
        String str = orderDomainService.refundApply(storeId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(str), HttpStatus.OK);
    }


    /**
     * 获取用户首次服务时间，和最后一次服务时间
     * @param userId
     * @return
     */
    @GetMapping("/service/time")
    public ResponseEntity queryServeceTime(String userId) {
        Map<String, String> map = orderService.orderFirstAndEnd(userId);
        return new ResponseEntity<>(ResponseUtils.getSuccess(map), HttpStatus.OK);
    }

    /**
     * 用户的上一单信息
     * @return
     */
    @GetMapping("/user/pre")
    public ResponseEntity userPre(String userIds) {
        Order order = orderService.userPre(userIds);
        if(order==null){
            throw new BusinessException(BusinessException.Type.DEFAULT,"订单不存在");
        }

        OrderUserResponseDto orderUserResponseDto = new OrderUserResponseDto();
        BeanUtils.copyProperties(order, orderUserResponseDto);

        return new ResponseEntity<>(ResponseUtils.getSuccess(orderUserResponseDto), HttpStatus.OK);
    }


    /**
    * @description: 生成手工单
    * @author: ch
    * @Param [orderManualSingle]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-08-05 14:42
    **/
    @PutMapping("/manual/single")
    public ResponseEntity manualSingle(@RequestBody @Valid OrderManualSingle orderManualSingle) {
        log.info("orderManualSingle order:{}", JSON.toJSONString(orderManualSingle));
        orderDomainService.editManualSingle(orderManualSingle);
        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }


    /**
     * 清洗支付老数据,后期可以删掉
     * @return
     */
/*    @RequestMapping("/pay/flush")
    public ResponseEntity flush(Long start, Long end) {
        log.info("/pay/flush order:{},{}", start, end);

        orderDomainService.flush(start, end);




        return new ResponseEntity<>(ResponseUtils.getSuccess(), HttpStatus.OK);
    }*/
}



